from jili.trade.constants import (
    bs,
    openclose,
    market,
    ordertype,
    product,
    status,
    optiontype
)
import PyCTP as ctp
status_ctp2ats = {
    ctp.THOST_FTDC_OAS_Submitted: status.submitting,
    ctp.THOST_FTDC_OAS_Accepted: status.submitting,
    ctp.THOST_FTDC_OAS_Rejected: status.rejected,
    ctp.THOST_FTDC_OST_NoTradeQueueing: status.working,
    ctp.THOST_FTDC_OST_PartTradedQueueing: status.parttraded,
    ctp.THOST_FTDC_OST_AllTraded: status.alltraded,
    ctp.THOST_FTDC_OST_Canceled: status.canceled
}

bs_ats2ctp = {
    bs.buy: ctp.THOST_FTDC_D_Buy,
    bs.sell: ctp.THOST_FTDC_D_Sell
}
bs_ctp2ats = {v: k for k, v in bs_ats2ctp.items()}
bs_ctp2ats[ctp.THOST_FTDC_PD_Long] = bs.buy
bs_ctp2ats[ctp.THOST_FTDC_PD_Short] = bs.sell

ordertype_ats2ctp = {
    ordertype.LIMIT: ctp.THOST_FTDC_OPT_LimitPrice,
    ordertype.MARKET: ctp.THOST_FTDC_OPT_AnyPrice
}
ordertype_ctp2ats = {v: k for k, v in ordertype_ats2ctp.items()}

openclose_ats2ctp = {
    openclose.open: ctp.THOST_FTDC_OF_Open,
    openclose.close: ctp.THOST_FTDC_OFEN_Close,
    openclose.closetoday: ctp.THOST_FTDC_OFEN_CloseToday,
    openclose.closeyesterday: ctp.THOST_FTDC_OFEN_CloseYesterday,
}
openclose_ctp2ats = {v: k for k, v in openclose_ats2ctp.items()}

market_ctp2ats = {
    "CFFEX": market.CFFEX,
    "SHFE": market.SHFE,
    "CZCE": market.CZCE,
    "DCE": market.DCE,
    "INE": market.INE
}
market_ats2ctp={v: k for k, v in market_ctp2ats.items()}

product_ctp2ats = {
    ctp.THOST_FTDC_PC_Futures: product.future,
    ctp.THOST_FTDC_PC_Options: product.option,
    ctp.THOST_FTDC_PC_SpotOption: product.option,
    ctp.THOST_FTDC_PC_Combination: product.spread
}

optiontype_ctp2ats = {
    ctp.THOST_FTDC_CP_CallOptions: optiontype.call,
    ctp.THOST_FTDC_CP_PutOptions: optiontype.put
}

submitorder2cpt={
    "obj":"InstrumentID",
    "marketcode":"ExchangeID",
    "bs":"Direction",
    "openclose":"CombOffsetFlag",
    "qty":"VolumeTotalOriginal",
    "pricetype":"",
    "price":"LimitPrice",
}

